package com.group01.community.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.group01.community.entity.SysLogininfor;
import com.group01.community.service.SysLogininforService;
import com.group01.community.utils.ExcelUtils;
import com.group01.community.utils.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;

/**
 * <p>
 * 系统访问记录 前端控制器
 * </p>
 *
 * @author iuoly
 * @since 2022-07-04
 */
@Api
@RestController
@RequestMapping("/sysLogininfor")
public class SysLogininforController {
    @Resource
    private SysLogininforService sysLogininforService;

    @ApiOperation("添加")
    @PostMapping
    public ResponseResult<String> add(@RequestBody SysLogininfor sysLogininfor) {
        sysLogininforService.save(sysLogininfor);
        return ResponseResult.ok("添加成功");
    }

    @ApiOperation("批量删除")
    @DeleteMapping("/{infoIds}")
    public ResponseResult<String> delete(@PathVariable Long[] infoIds) {
        sysLogininforService.removeByIds(Arrays.asList(infoIds));
        return ResponseResult.ok("删除成功");
    }

    @ApiOperation("清空")
    @DeleteMapping("/clear")
    public ResponseResult<String> clear() {
        sysLogininforService.remove(null);
        return ResponseResult.ok("清空成功");
    }

    @ApiOperation("修改")
    @PutMapping
    public ResponseResult<String> update(@RequestBody SysLogininfor sysLogininfor) {
        sysLogininforService.updateById(sysLogininfor);
        return ResponseResult.ok("修改成功");
    }

    @ApiOperation("带条件查询")
    @PostMapping("/condition")
    public ResponseResult<IPage<SysLogininfor>> selectCondition(@RequestBody SysLogininfor sysLogininfor, Long current, Long size) {
        return ResponseResult.ok(sysLogininforService.selectCondition(sysLogininfor, current, size));
    }

    @ApiOperation("导出")
    @GetMapping("/export")
    public ResponseResult<String> export(HttpServletResponse resp) {
        ExcelUtils.export(SysLogininfor.class, sysLogininforService, resp, "登录日志信息");
        return ResponseResult.ok("ok");
    }
}

